package com.yb.bussiness.shoper;

import java.util.List;
import java.util.Map;

import com.yb.base.dao.BaseDao;
import com.yb.base.dao.IBaseDao;
import com.yb.domain.goods.TgCase;
import com.yb.util.framework.PageUtil;

public class TgCaseServiceImpl implements TgCaseService {

	private IBaseDao<TgCase, Long> dao;

	private String FIND_SQL = "SELECT * FROM t_g_case where 1=1 ";

	public TgCaseServiceImpl() {
		dao = new BaseDao<TgCase, Long>(TgCase.class);
	}

	public void delTgStore(Long id) {
		dao.deleteById(id);
	}

	public PageUtil findList(Map<String, String> map, int page, int row) {
		return null;
	}

	public TgCase read(Long id) {
		return dao.read(id);
	}

	public void saveOrUpdate(TgCase obj) {
		dao.saveOrUpdate(obj);
	}

	public TgCase findCaseBybid(Long lid) {
		String sql = FIND_SQL + " and brandId=?";
		List<TgCase> list = dao.findList(sql, new Object[] { lid });
		if(null!=list && list.size()>0)
		return list.get(0);
		return null;
	}

	public int count(Map<String, String> parameMap) {
		int count = 0;
		try {
			String str = "  SELECT count(*) FROM t_g_case b WHERE b.brandId=?";
			if (parameMap.get("name") != null
					&& !"".equals(parameMap.get("name"))) {
				str += "  and b.title LIKE   '%" + parameMap.get("name") + "%'";
			}
			List<Object[]> objAryList = dao.findObjectArryList(str,new Object[]{parameMap.get("brandId")});
			if (null != objAryList && objAryList.size() > 0) {
				Object[] obj = objAryList.get(0);
				count = new Integer(obj[0].toString());
			}
		} catch (Exception e) {
			return 0;
		}
		return count;
	}

	public List<TgCase> findcases(Map<String, String> parameMap) {
		try {
			String str = " SELECT * FROM t_g_case b WHERE b.brandId=?";
			if (parameMap.get("name") != null
					&& !"".equals(parameMap.get("name"))) {
				str += "  and b.title LIKE   '%" + parameMap.get("name") + "%'";
			}
			if (parameMap.get("page") != null && parameMap.get("row") != null) {
				int start = Integer.parseInt(parameMap.get("page")) - 1;
				int limit = Integer.parseInt(parameMap.get("row"));
				str += " limit " + start * limit + "," + limit;
			}
			List<TgCase> list = dao.findList(str,new Object[]{parameMap.get("brandId")});
			return list;
		} catch (Exception e) {
			return null;
		}
	}

}
